package com.db.device.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.db.core.dto.PageDto;
import com.db.core.vo.PageResult;
import com.db.device.dto.DevicePageDto;
import com.db.device.entity.Device;
import com.db.device.mapper.DeviceMapper;
import com.db.device.service.DeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.db.deviceType.entity.DeviceType;
import com.db.product.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 设备表 服务实现类
 * </p>
 *
 * @author vodka
 * @since 2023-10-30
 */
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {


    @Autowired
    private DeviceMapper deviceMapper;

    public PageResult page(DevicePageDto devicePageDto){
        //获取分页信息
        Integer size = devicePageDto.getSize();
        Integer now = devicePageDto.getNow();
        //开始查询
        long start = (now - 1) * size;
        List<Device> page = baseMapper.page(devicePageDto, start);
        //查询总记录数
        long total = page.size();
        //计算总页数
        long pages = (total + size - 1) / size;
        //将数据封装到pageBean
        PageResult<Device> pageResult = new PageResult<>();
        pageResult.setTotal(total);
        pageResult.setPages(pages);
        pageResult.setList(page);
        return pageResult;
    }

}
